package com.cwj.algorithm.graph;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author chenwujie
 * @date 2020-12-22 13:25
 */
public class Graph {
    /**
     * 顶点数量
     */
    private int V;
    /**
     * 边数量
     */
    private int E;
    /**
     * 邻接表
     */
    private final Deque<Integer>[] adj;

    public Graph(int vertexLength){
        this.V = vertexLength;
        this.E = 0;
        adj = new LinkedList[vertexLength];
        for (int i = 0; i < vertexLength; i++) {
            adj[i] = new LinkedList<Integer>();
        }
    }

    /**
     * 添加一条无向边
     * @param v
     * @param w
     */
    public void addEdge(int v, int w){
        adj[v].add(w);
        adj[w].add(v);
        E++;
    }

    /**
     * 根据顶点获取对应的所有边
     * @param v
     * @return
     */
    public Deque<Integer> getVertexes(int v){
        return adj[v];
    }

    public int getE() {
        return E;
    }

    public int getV() {
        return V;
    }
}
